const axios = require('axios');
const MockAdapter = require('axios-mock-adapter');
const normalAxios = axios.create();
const mockAxios = axios.create();
import url_config from "./config";
import reqTools from "../utils/reqTools";

// mock 数据
var mock = new MockAdapter(mockAxios);

mock.onPost('/addAgentType').reply((config) => {
  return new Promise(function(resolve, reject) { 
    reqTools.post('/api/setAgentType', config.data).then((res) => {
     resolve([200, res ]);
   }).catch((err) => {
     resolve([500, err ]);
   });
 });
});

mock.onGet('/agentTypePage').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/setAgentType',
    config).then((res) => {
      resolve([200, res.data]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});

mock.onGet('/findAllAgentType').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/setAgentType/findAllAgentType',
    config).then((res) => {
      resolve([200, res.data]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});

mock.onGet('/maxSort').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/setAgentType/findMaxSort',config).then((res) => {
      resolve([200, res.data]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});



mock.onDelete('/deleteAgentType').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.delete( '/api/setAgentType/'+config.id).then((res) => {
      resolve([200, res ]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});

mock.onDelete('/deletesAgentType').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.delete( '/api/setAgentType/deletes',config).then((res) => {
      resolve([200, res ]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});

mock.onPut('/updateAgentType').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.put( '/api/setAgentType',config.data,
     ).then((res) => {
      resolve([200, res ]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});

mock.onGet('/maxSort').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/sysDict/findMaxSortByType',
    config).then((res) => {
      resolve([200, res.data]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
export default mockAxios;
